package com.summer.tools.flowable.controller;


import com.summer.tools.common.model.SimplePage;
import com.summer.tools.common.utils.ResponseResult;
import com.summer.tools.flowable.VO.FormModel;
import com.summer.tools.flowable.service.IProcessFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 表单控制器
 * </p>
 *
 * @author john.wang
 * @since 2021-08-19
 */
@RestController
@RequestMapping("/form")
@Api(tags = "表单管理")
public class ProcessFormController {

    @Resource
    private IProcessFormService formService;

    @PostMapping
    @ApiOperation("添加表单")
    public ResponseResult<?> addForm(@RequestBody FormModel form) {
        this.formService.addForm(form);
        return ResponseResult.SUCCESS;
    }

    @PutMapping
    @ApiOperation("编辑表单")
    public ResponseResult<?> updateForm(@RequestBody FormModel form) {
        this.formService.updateForm(form);
        return ResponseResult.SUCCESS;
    }

    @GetMapping
    @ApiOperation("根据formKey查询表单")
    public ResponseResult<FormModel> getForm(@RequestParam String formKey) {
        return ResponseResult.success(this.formService.getForm(formKey));
    }

    @GetMapping
    @ApiOperation("表单列表")
    public ResponseResult<SimplePage<FormModel>> list(@RequestParam(required = false) String name) {
        return ResponseResult.success(this.formService.list(name));
    }



}

